<?php
namespace app\material\controller;
use app\AdminRest;


use app\material\model\Brochure;
use app\material\model\Config;
use app\material\model\File;
use app\material\model\Folder;
use think\App;




class AdminData extends AdminRest
{

    protected $model;

    protected $brochure_model;

    protected $file_model;

    protected $folder_model;

    public function __construct(App $app) {

        parent::__construct($app);

        $this->model  = new File();

        $this->brochure_model  = new Brochure();

        $this->file_model = new File();

        $this->folder_model  = new Folder();

    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-24 15:43
     * @功能说明:宣传册列表
     */
    public function brochureList(){

        $input = $this->_param;

        $dis[] = ['a.uniacid','=',$this->_uniacid];

        $dis[] = ['a.status','>',-1];

        if(!empty($input['title'])){

            $dis[] = ['a.title','like','%'.$input['title'].'%'];
        }

        $data = $this->brochure_model->dataList($dis,$input['limit']);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-24 15:51
     * @功能说明:添加宣传册
     */
    public function brochureAdd(){

        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $res = $this->brochure_model->dataAdd($input);

        return $this->success($res);

    }




    /**
     * @author chenniang
     * @DataTime: 2021-06-24 15:51
     * @功能说明:添加宣传册
     */
    public function brochureUpdate(){

        $input = $this->_input;

        $dis = [

            'id' => $input['id']
        ];

        $input['uniacid'] = $this->_uniacid;

        $res = $this->brochure_model->dataUpdate($dis,$input);

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-25 10:35
     * @功能说明:宣传册详情
     */
    public function brochureInfo(){

        $input = $this->_param;

        $dis = [

            'id' => $input['id']
        ];

        $res = $this->brochure_model->dataInfo($dis);

        return $this->success($res);
    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-24 16:15
     * @功能说明:文件夹列表
     */
    public function folderList(){

        $input = $this->_param;

        $dis[] = ['uniacid','=',$this->_uniacid];

        $dis[] = ['status','=',1];

        $dis[] = ['user_id','=',0];

        if(!empty($input['title'])){

            $dis[] = ['title','like','%'.$input['title'].'%'];
        }

        $data = $this->folder_model->dataList($dis);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-28 16:47
     * @功能说明:文件夹列表分页
     */
    public function folderPageList(){

        $input = $this->_param;

        $dis[] = ['uniacid','=',$this->_uniacid];

        $dis[] = ['status','>',-1];

        $dis[] = ['pid','=',0];

        $dis[] = ['user_id','=',0];

        if(!empty($input['title'])){

            $dis[] = ['title','like','%'.$input['title'].'%'];

        }

        $data = $this->folder_model->dataPageList($dis,$input['limit']);

        return $this->success($data);


    }



    /**
     * @author chenniang
     * @DataTime: 2021-06-24 16:22
     * @功能说明:添加文件夹
     */
    public function folderAdd(){

        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $res = $this->folder_model->dataAdd($input);

        return $this->success($res);



    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-24 16:38
     * @功能说明:编辑文件夹
     */
    public function folderUpdate(){

        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $dis = [

          'id' => $input['id']
        ];

        $res = $this->folder_model->dataUpdate($dis,$input);
        //下架和删除会影响下级
        if(isset($input['status'])&&in_array($input['status'],[-1,0])){

            $folder_id = $this->folder_model->getLowId($input['id']);
        }
        //上架会影响上级
        if(isset($input['status'])&&in_array($input['status'],[1])){

            $folder_id = $this->folder_model->reset($input['id']);

        }

        if(!empty($folder_id)){

            $where[] = ['status','>',-1];

            $where[] = ['id','in',$folder_id];

            $this->folder_model->dataUpdate($where,['status'=>$input['status']]);

        }

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-25 10:35
     * @功能说明:文件夹详情
     */
    public function folderInfo(){

        $input = $this->_param;

        $dis = [

            'id' => $input['id']
        ];

        $res = $this->folder_model->dataInfo($dis);

        return $this->success($res);
    }
    /**
     * @author chenniang
     * @DataTime: 2021-06-24 16:42
     * @功能说明:文件列表
     */
    public function fileList(){

        $input = $this->_param;

        $dis[] = ['a.uniacid','=',$this->_uniacid];

        $dis[] = ['a.status','>',-1];

        $dis[] = ['user_id','=',0];

        if(!empty($input['title'])){

            $dis[] = ['a.title','like','%'.$input['title'].'%'];
        }

        $data = $this->file_model->dataList($dis,$input['limit']);

        return $this->success($data);


    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-24 15:51
     * @功能说明:添加文件
     */
    public function fileAdd(){

        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $res = $this->file_model->dataAdd($input);

        return $this->success($res);

    }




    /**
     * @author chenniang
     * @DataTime: 2021-06-24 15:51
     * @功能说明:添加文件
     */
    public function fileUpdate(){

        $input = $this->_input;

        $dis = [

            'id' => $input['id']
        ];

        $input['uniacid'] = $this->_uniacid;

        $res = $this->file_model->dataUpdate($dis,$input);

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-25 10:35
     * @功能说明:文件详情
     */
    public function fileInfo(){

        $input = $this->_param;

        $dis = [

            'id' => $input['id']
        ];

        $res = $this->file_model->dataInfo($dis);

        $res['folder_text'] = $this->folder_model->reset($res['folder_id']);

        return $this->success($res);
    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-29 14:35
     * @功能说明:配置详情
     */
    public function configInfo(){

        $config = new Config();

        $dis = [

            'uniacid' => $this->_uniacid
        ];

        $data = $config->dataInfo($dis);

        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2021-06-29 14:37
     * @功能说明:修改配置
     */
    public function configUpdate(){

        $input = $this->_input;

        $config = new Config();

        $dis = [

            'uniacid' => $this->_uniacid
        ];

        $data = $config->dataUpdate($dis,$input);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2021-08-03 15:51
     * @功能说明:转图片
     */
    public function base64ToPng(){

        $input = $this->_input;

        $data = $this->file_model->base64ToPng($input['img']);

        return $this->success($data);

    }



    /**
     * @author chenniang
     * @DataTime: 2021-07-07 10:56
     * @功能说明:pptTopdf
     */
    public function pptTopdf(){

        $input = $this->_param;

        $input['ppt'] = FILE_UPLOAD_PATH.$input['ppt'];

        $data = $this->file_model->pptTopdf($input['ppt']);

//        $file = file_get_contents($data);//读
//
//        $data = base64_encode($file);//转换

//        $path = MATER_UPLOAD_PATH.date('Y-m-d',time()).'/pdf/';
//
//        $imageName = "/25220_".date("His",time())."_".rand(1111,9999).'.pdf';
//
//        file_put_contents($path.$imageName, $data);//写

        return $this->success($data);


    }






}
